#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head)
    {
        if (head == nullptr)
            return head;
        ListNode* cur, * NewHead;
        NewHead = cur = new ListNode(-1);
        cur->next = head;
        while (cur->next != nullptr && cur->next->next != nullptr)
        {
            if (cur->next->val == cur->next->next->val)
            {
                int x = cur->next->val;
                while (cur->next != nullptr && cur->next->val == x)
                {
                    cur->next = cur->next->next;
                }
            }
            else
            {
                cur = cur->next;
            }
        }
        return NewHead->next;
    }
};

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head)
    {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode* cur = head->next;
        if (head->val == cur->val)
        {
            while (cur != nullptr && cur->val == head->val)
            {
                cur = cur->next;
            }
            head = deleteDuplicates(cur);
        }
        else
        {
            head->next = deleteDuplicates(cur);
        }
        return head;
    }
};

